// 使用函数的电话费，电费，水费计算程序

#include <iostream>
using namespace std;

float CalcTotals(float costs[][3], float* p_cost, float* e_cost, float* w_cost);

int main() {
    float costs[12][3];
    float phone, elec, water;

    float totals = CalcTotals(costs, &phone, &elec, &water);

    cout << "年度总费用为: " << totals << "\n";
    cout << "电话费为: " << phone << "\n";
    cout << "电费为: " << elec << "\n";
    cout << "水费为: " << water << "\n";
}


float CalcTotals(float costs[][3], float* p_cost, float* e_cost, float* w_cost) {
    for (int i = 0; i < 3; i++) {

        // 12个月份总额
        float sum = 0.0f;
        for (int j = 0; j < 12; j++) {
            sum += costs[j][i];
        }
        switch (i) {
            case 0:
                *p_cost = sum;
                break;
            case 1:
                *e_cost = sum;
                break;
            default:
                *w_cost = sum;
                break;
        }
    }
    return *p_cost + *e_cost + *w_cost;
}